package com.sdjz.club.club.common.lang;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class CommonResult<T> implements Serializable {

    private int code;
    private String msg;
    private T data;

    public CommonResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
        this.data = null;
    }

    public CommonResult(T data) {
        this.code = 200;
        this.msg = "成功";
        this.data = data;
    }

    public static CommonResult succ() {
        return succ(200, "操作成功", null);
    }

    public static CommonResult succ(Object data) {
        return succ(200, "操作成功", data);
    }

    public static CommonResult succ(int code, String msg, Object data) {
        CommonResult r = new CommonResult();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public static CommonResult fail(String msg) {
        return fail(400, msg, null);
    }

    public static CommonResult fail(int code, String msg, Object data) {
        CommonResult r = new CommonResult();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

}
